<!DOCTYPE HTML>
<html  lang="zh" xmlns:th="http://www.thymeleaf.org">
<meta charset="utf-8">
<link th:href="@{/ajax/libs/cropbox/cropbox.css}" rel="stylesheet"/>
<link th:href="@{/ajax/libs/jquery-layout/jquery.layout-latest.css}" rel="stylesheet"/>
<head th:include="include :: header"></head>
<body class="white-bg">
<div class="wrapper wrapper-content animated fadeInRight ibox-content">
    <form class="form-horizontal m" id="form-xyzlb-edit" th:object="${xyzlb}">
        <input id="studentId" name="studentId" th:field="*{studentId}"  type="hidden">
        <input name="deptId"  type="hidden"  th:field="*{deptId}" id="treeId"/>
        <div class="form-group">
            <label class="col-sm-3 control-label">机构名称：</label>
            <div class="col-sm-8">
                <input name="deptName" class="form-control" type="text" onclick="selectDeptTree()" readonly="true" id="treeName" th:field="*{deptName}">
            </div>
        </div>
        <!--<div class="form-group">-->
        <!--<label class="col-sm-3 control-label">学员编号：</label>-->
        <!--<div class="col-sm-8">-->
        <!--<input id="xybh" name="xybh" th:field="*{xybh}" class="form-control" type="text">-->
        <!--</div>-->
        <!--</div>-->
        <div class="form-group">
            <label class="col-sm-3 control-label">姓名：</label>
            <div class="col-sm-8">
                <input id="studentName" name="studentName" th:field="*{studentName}" class="form-control" type="text">
            </div>
        </div>
        <div class="form-group">
            <label class="col-sm-3 control-label">性别：</label>
            <div class="col-sm-8">
                <select id="sex" class="form-control m-b" th:with="type=${@dict.getType('sys_user_sex')}">
                    <option th:each="dict : ${type}" th:text="${dict.dictLabel}" th:value="${dict.dictValue}" th:field="*{sex}"></option>
                </select>
            </div>
        </div>
        <div class="form-group">
            <label class="col-sm-3 control-label">民族：</label>
            <div class="col-sm-8">
                <input id="nation" name="nation" th:field="*{nation}" class="form-control" type="text">
            </div>
        </div>
        <div class="form-group">
            <label class="col-sm-3 control-label">手机号码：</label>
            <div class="col-sm-8">
                <input id="studentTelephone" name="studentTelephone" th:field="*{studentTelephone}" class="form-control" type="text">
            </div>
        </div>
        <div class="form-group">
            <label class="col-sm-3 control-label">生日：</label>
            <div class="col-sm-8">
                <input id="birthday" name="birthday" class="form-control pick-time birthday_edit" type="text" th:value="${#dates.format(xyzlb.birthday,'yyyy-MM-dd')}" readonly="readonly">
            </div>
        </div>

        <div class="form-group">
            <label class="col-sm-3 control-label">职业背景：</label>
            <div class="col-sm-8">
                <input id="occupation" name="occupation" th:field="*{occupation}" class="form-control" type="text">
            </div>
        </div>
        <div class="form-group">
            <label class="col-sm-3 control-label">婚姻：</label>
            <div class="col-sm-8">
                <select id="marriage" class="form-control m-b" th:with="type=${@dict.getType('zl_xyzlb_huny')}">
                    <option th:each="dict : ${type}" th:text="${dict.dictLabel}" th:value="${dict.dictValue}" th:field="*{marriage}"></option>
                </select>
            </div>
        </div>
        <div class="form-group">
            <label class="col-sm-3 control-label">小孩：</label>
            <div class="col-sm-8">
                <select id="child" class="form-control m-b" th:with="type=${@dict.getType('zl_hyzlb_xiaoh')}">
                    <option th:each="dict : ${type}" th:text="${dict.dictLabel}" th:value="${dict.dictValue}" th:field="*{child}"></option>
                </select>
            </div>
        </div>
        <div class="form-group">
            <label class="col-sm-3 control-label">住址：</label>
            <div class="col-sm-8">
                <input id="studentAddress" name="studentAddress" th:field="*{studentAddress}" class="form-control" type="text">
            </div>
        </div>
        <div class="form-group">
            <label class="col-sm-3 control-label">身份证：</label>
            <div class="col-sm-8">
                <input id="identity" name="identity" th:field="*{identity}" class="form-control" type="text">
            </div>
        </div>
        <div class="form-group">
            <label class="col-sm-3 control-label">身份证正面：</label>
            <div class="col-sm-8">
                <input id="identityz" name="identityz" class="form-control" type="text" th:field="*{identityz}" readonly="readonly">
                <button id="up_identityz" type="button">点击上传</button>
            </div>
        </div>
        <div class="form-group">
            <label class="col-sm-3 control-label">身份证反面：</label>
            <div class="col-sm-8">
                <input id="identityf" name="identityf" class="form-control" type="text" th:field="*{identityf}" readonly="readonly">
                <button id="up_identityf" type="button">点击上传</button>
            </div>
        </div>
        <!--<div class="container">-->
        <!--<div class="imageBox">-->
        <!--<div class="thumbBox"></div>-->
        <!--<div class="spinner" style="display: none">请大佬修改身份证图片...</div>-->
        <!--</div>-->
        <!--<div class="action">-->
        <!--<div class="new-contentarea tc">-->

        <!--<a href="javascript:void(0)" class="upload-img"> <label for="identityz_file">修改身份证图像</label> </a>-->
        <!--<input type="file" class="" name="identityz_file" id="identityz_file" accept="image/*"/>-->
        <!--</div>-->
        <!--<input type="button" id="btnCrop" class="Btnsty_peyton" value="裁切" />-->
        <!--<input type="button" id="btnZoomIn" class="Btnsty_peyton" value="+" />-->
        <!--<input type="button" id="btnZoomOut" class="Btnsty_peyton" value="-" />-->

        <!--</div>-->
        <!--<div class="cropped"></div>-->
        <!--</div>-->
        <div class="form-group">
            <label class="col-sm-3 control-label">课程类型：</label>
            <div class="col-sm-8">
                <select id="courseType" class="form-control m-b" th:with="type=${@dict.getType('zl_song_leibie')}">
                    <option th:each="dict : ${type}" th:text="${dict.dictLabel}" th:value="${dict.dictValue}" th:field="*{courseType}"></option>
                </select>
            </div>
        </div>
        <div class="form-group">
            <label class="col-sm-3 control-label">收费等级：</label>
            <div class="col-sm-8">
                <select id="chargeLevel" class="form-control m-b" th:with="type=${@dict.getType('zl_subject_level')}">
                    <option th:each="dict : ${type}" th:text="${dict.dictLabel}" th:value="${dict.dictValue}" th:field="*{chargeLevel}"></option>
                </select>
            </div>
        </div>
        <div class="form-group">
            <label class="col-sm-3 control-label">收费金额：</label>
            <div class="col-sm-8">
                <input id="amountCharges" name="amountCharges" class="form-control" type="text" readonly  unselectable="on" th:field="*{amountCharges}">
            </div>
        </div>
        <div class="form-group">
            <label class="col-sm-3 control-label">推荐人：</label>
            <div class="col-sm-8">
                <input id="recommender" name="recommender" th:field="*{recommender}" class="form-control" type="text">
            </div>
        </div>

        <div class="form-group">
            <label class="col-sm-3 control-label">缴费日期：</label>
            <div class="col-sm-8">
                <input id="paymentDate" name="paymentDate" class="form-control pick-time" type="text" th:value="${#dates.format(xyzlb.paymentDate,'yyyy-MM-dd')}" readonly="readonly">
            </div>
        </div>
        <div class="form-group">
            <label class="col-sm-3 control-label">接待教师：</label>
            <div class="col-sm-8">
                <input id="receptionist" name="receptionist" th:field="*{receptionist}" class="form-control" type="text">
            </div>
        </div>
        <div class="form-group">
            <label class="col-sm-3 control-label">来源渠道：</label>
            <div class="col-sm-8">
                <input id="sourceChannel" name="sourceChannel" th:field="*{sourceChannel}" class="form-control" type="text">
            </div>
        </div>

        <div class="form-group">
            <label class="col-sm-3 control-label">备注：</label>
            <div class="col-sm-8">
                <input id="remark" name="remark" th:field="*{remark}" class="form-control" type="text">
            </div>
        </div>
    </form>
</div>
<div th:include="include::footer"></div>
<script th:src="@{/ajax/libs/cropbox/cropbox.js}"></script>
<script th:src="@{/ajax/libs/jquery-layout/jquery.layout-latest.js}"></script>
<script type="text/javascript">
    var options_year_class = eval("[[${@dict.getTypeJson('zl_subject_year')}]]".replace(/&quot;/g, "'"));
    var options_level_class = eval("[[${@dict.getTypeJson('zl_subject_level')}]]".replace(/&quot;/g, "'"));
    var chargeLevel = "[[${xyzlb.chargeLevel}]]";
    var options;
    // 联动选项设置
    function reashClass() {

        var _options_html = "";
        if ($("#courseType").val() == "level") {
            options = options_level_class;
        } else {
            console.log("year")
            options = options_year_class;

        }
        for (var i = 0; i < options.length; i++) {
            var option = options[i];
            console.log(option)
            _options_html = _options_html + "<option value='" + option.dictValue + "' data-remark='"+option.remark+"'>" +  option.dictLabel + "</option>"
        }
        $("#chargeLevel").html(_options_html);
        $("#amountCharges").val($("#chargeLevel option:selected").attr("data-remark"))
    }


    //初始化设置chargeLevel 选中项
    function init(){
        reashClass();
        for (var i = 0; i < options.length; i++) {
            var option = options[i];
            if (option.dictValue==chargeLevel){
                console.log(option.dictValue)
                $("#chargeLevel").val(option.dictValue);
            }
        }
        $("#amountCharges").val($("#chargeLevel option:selected").attr("data-remark"))
    }
    init();
    $("#courseType").on("change", function () {
        reashClass();
    })

    $("#chargeLevel").on("change", function () {
        $("#amountCharges").val($("#chargeLevel option:selected").attr("data-remark"))
    })


    var prefix = ctx + "project/xyzlb"
    $("#form-xyzlb-edit").validate({
        rules:{
            xxxx:{
                required:true,
            },
        }
    });

    function submitHandler() {
        if ($.validate.form()) {
            edit();
        }
    }
    function edit() {
        var formdata = new FormData();
        //var img = cropper.getBlob();
        //formdata.append("identityz_file", img);
        formdata.append("identityz", $("input[name='identityz']").val());
        formdata.append("identityf", $("input[name='identityf']").val());
        formdata.append("studentId",$("input[name='studentId']").val());
        formdata.append("deptId", $("input[name='deptId']").val());
        formdata.append("deptName", $("input[name='deptName']").val());
        formdata.append("studentName", $("input[name='studentName']").val());
        formdata.append("nation", $("input[name='nation']").val());
        formdata.append("studentTelephone", $("input[name='studentTelephone']").val());
        formdata.append("birthday", $("input[name='birthday']").val());
        formdata.append("occupation", $("input[name='occupation']").val());
        formdata.append("marriage", $("#marriage option:selected").val());
        formdata.append("sex", $("#sex option:selected").val());
        formdata.append("child", $("#child option:selected").val());
        formdata.append("studentAddress", $("input[name='studentAddress']").val());
        formdata.append("identity", $("input[name='identity']").val());
        formdata.append("chargeLevel", $("#chargeLevel option:selected").val());
        formdata.append("recommender", $("input[name='recommender']").val());
        formdata.append("courseType", $("#courseType option:selected").val());
        formdata.append("paymentDate", $("input[name='paymentDate']").val());
        formdata.append("receptionist", $("input[name='receptionist']").val());
        formdata.append("sourceChannel", $("input[name='sourceChannel']").val());
        formdata.append("remark", $("input[name='remark']").val());
        formdata.append("amountCharges", $("input[name='amountCharges']").val());

        $.ajax({
            type : "POST",
            url : ctx + "project/xyzlb/edit",
            data : formdata,
            processData: false,
            contentType: false,
            error : function(request) {
                $.modal.alertError("系统错误");
            },
            success : function(data) {
                $.operate.saveSuccess(data);
            }
        });
    }
    /*用户管理-新增-选择部门树*/
    function selectDeptTree() {
        var treeId = $("#treeId").val();
        var deptId = $.common.isEmpty(treeId) ? "100" : $("#treeId").val();
        var url = ctx + "system/dept/selectDeptTree/" + deptId;
        var options = {
            title: '选择部门',
            width: "380",
            url: ctx + "system/dept/selectDeptTree/" + deptId,
            callBack: doSubmit
        };
        $.modal.openOptions(options);
    }

    function doSubmit(index, layero){
        var tree = layero.find("iframe")[0].contentWindow.$._tree;
        if ($.tree.notAllowParents(tree)) {
            var body = layer.getChildFrame('body', index);
            $("#treeId").val(body.find('#treeId').val());
            $("#treeName").val(body.find('#treeName').val());
            layer.close(index);
        }
    }
    $("#up_identityz").on('click', function () {
        var identityz  = $('#identityz').val()
        var height = ($(window).height() - 50);
        layer.open({
            type: 2,
            area: ['80%', height + 'px'],
            fix: false,
            //不固定
            maxmin: true,
            shade: 0.3,
            title: '图片上传',
            content: ctx + 'common/img?imgType=card&elem=identityz' + ($.common.isEmpty(identityz) ? '' : '&imgName=' + identityz),
            // 弹层外区域关闭
            shadeClose: true,
            success: function (layero, index) {
            }
        });
    });
    $("#up_identityf").on('click', function () {
        var identityf  = $('#identityf').val()
        var height = ($(window).height() - 50);
        layer.open({
            type: 2,
            area: ['80%', height + 'px'],
            fix: false,
            //不固定
            maxmin: true,
            shade: 0.3,
            title: '图片上传',
            content: ctx + 'common/img?imgType=card&elem=identityf' + ($.common.isEmpty(identityf) ? '' : '&imgName=' + identityf),
            // 弹层外区域关闭
            shadeClose: true,
            success: function (layero, index) {
            }
        });
    })
</script>
</body>
</html>
